package com.data.controller;

import com.data.entity.User;
import com.data.service.IUserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * Created by wuyal on 2018/3/20.
 * Controller 类
 */
@Controller
@RequestMapping("/sort")
public class WebController {

    @Resource
    IUserService UserService;

    /**
     * 使用 thymeleaf 渲染List.html
      * @param model
     * @return
     */
    @RequestMapping("/list")
    public String list(Model model) {
        List<User> list = UserService.queryUserDataBySort(null);
        model.addAttribute("list",list);
        return "user/List";
    }

    /**
     * 提供 ajax json 数据

     */
    @RequestMapping(value = "/userlist")
    @ResponseBody
    public List<User> getList(@RequestParam String SortCol) {
        List<User> list = UserService.queryUserDataBySort(SortCol);
        return list;

    }
}